package com.yxw.live_vod_boot.service.impl;



import lombok.extern.slf4j.Slf4j;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import com.yxw.yxnet_cd_center.common.utils.BaseDateTime;
import org.springframework.transaction.annotation.Transactional;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.hutool.core.util.ObjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yxw.live_vod_boot.entity.YxLiveWatchLogEntity;
import com.yxw.live_vod_boot.dto.YxLiveWatchLogDTO;
import com.yxw.live_vod_boot.dto.YxLiveWatchLogAddDTO;
import com.yxw.live_vod_boot.dto.YxLiveWatchLogQueryDTO;
import com.yxw.live_vod_boot.mapper.YxLiveWatchLogMapper;
import com.yxw.live_vod_boot.service.IYxLiveWatchLogService;



/*** 
*@author Jiaxu.Huang
*@date 2023/12/18 17:59:06
*@update 2023/12/18 17:59:06
**/
@Slf4j
@Service
//public class YxLiveWatchLogServiceImpl  extends ServiceImpl<YxLiveWatchLogMapper, YxLiveWatchLogEntity> implements IYxLiveWatchLogService{
public class YxLiveWatchLogServiceImpl  implements IYxLiveWatchLogService{
    @Autowired
    private YxLiveWatchLogMapper oYxLiveWatchLogMapper;
    /*** 
    * 新增
    * @param oYxLiveWatchLogDTO
    * @return BaseResult
    **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResult insertYxLiveWatchLog(YxLiveWatchLogAddDTO oYxLiveWatchLogAddDTO)
    {
        YxLiveWatchLogEntity oYxLiveWatchLogEntity = new YxLiveWatchLogEntity();
        BeanUtil.copyProperties(oYxLiveWatchLogAddDTO, oYxLiveWatchLogEntity);
        oYxLiveWatchLogEntity.setCreateTime(System.currentTimeMillis());
        oYxLiveWatchLogMapper.insert(oYxLiveWatchLogEntity);
        //oYxLiveWatchLogDTO.setId(oYxLiveWatchLogEntity.getId());
        return BaseResult.success(oYxLiveWatchLogEntity);
    }
    /*** 
    * 修改
    * @param oYxLiveWatchLogDTO
    * @return BaseResult
    **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResult updateYxLiveWatchLogById(YxLiveWatchLogDTO oYxLiveWatchLogDTO)
    {
        YxLiveWatchLogEntity oYxLiveWatchLogEntity = new YxLiveWatchLogEntity();
        BeanUtil.copyProperties(oYxLiveWatchLogDTO, oYxLiveWatchLogEntity);
        oYxLiveWatchLogMapper.updateById(oYxLiveWatchLogEntity);
        return BaseResult.success();
    }
    /*** 
    * 删除
    * @param id
    * @return BaseResult
    **/
    @Override
    @Transactional(rollbackFor = Exception.class)
    public BaseResult deleteYxLiveWatchLogById(Long id)
    {
        if(ObjectUtil.isEmpty(id))
        {
            return BaseResult.failed("Id不能为空值");
        }
        oYxLiveWatchLogMapper.deleteById(id);
        return BaseResult.success();
    }
    /*** 
    * 根据id查找
    * @param id
    * @return YxLiveWatchLogEntity
    **/
    @Override
    public YxLiveWatchLogEntity selectYxLiveWatchLogById(Long id)
    {
        if(ObjectUtil.isEmpty(id))
        {
            return null;
        }
        return oYxLiveWatchLogMapper.selectById(id);
    }
    /*** 
    * 自定义查询
    * @param oYxLiveWatchLogDTO
    * @return List<YxLiveWatchLogEntity>
    **/
    @Override
    public List<YxLiveWatchLogEntity> selectYxLiveWatchLogList(YxLiveWatchLogQueryDTO oYxLiveWatchLogQueryDTO)
    {
        QueryWrapper<YxLiveWatchLogEntity> oYxLiveWatchLogQueryWrapper = new QueryWrapper();
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getId()),"id",oYxLiveWatchLogQueryDTO.getId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getLiveShopId()),"live_shop_id",oYxLiveWatchLogQueryDTO.getLiveShopId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getShopId()),"shop_id",oYxLiveWatchLogQueryDTO.getShopId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getLiveId()),"live_id",oYxLiveWatchLogQueryDTO.getLiveId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchUserId()),"watch_user_id",oYxLiveWatchLogQueryDTO.getWatchUserId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchStartTime()),"watch_start_time",oYxLiveWatchLogQueryDTO.getWatchStartTime());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchEndTime()),"watch_end_time",oYxLiveWatchLogQueryDTO.getWatchEndTime());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchDuration()),"watch_duration",oYxLiveWatchLogQueryDTO.getWatchDuration());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchLength()),"watch_length",oYxLiveWatchLogQueryDTO.getWatchLength());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getNetSpeed()),"net_speed",oYxLiveWatchLogQueryDTO.getNetSpeed());
        oYxLiveWatchLogQueryWrapper.ge(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getCreateTimeStart()),"create_time",oYxLiveWatchLogQueryDTO.getCreateTimeStart());
        oYxLiveWatchLogQueryWrapper.le(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getCreateTimeEnd()),"create_time",oYxLiveWatchLogQueryDTO.getCreateTimeEnd());
        //List<YxLiveWatchLogEntity> oListYxLiveWatchLog = oYxLiveWatchLogMapper.selectList(oYxLiveWatchLogQueryWrapper);
        //return Res.ok(oListYxLiveWatchLog);
        return  oYxLiveWatchLogMapper.selectList(oYxLiveWatchLogQueryWrapper);
    }
    /*** 
    * 自定义统计
    * @param oYxLiveWatchLogEntity
    * @return Integer
    **/
    @Override
    public Integer selectYxLiveWatchLogCount(YxLiveWatchLogQueryDTO oYxLiveWatchLogQueryDTO)
    {
        QueryWrapper<YxLiveWatchLogEntity> oYxLiveWatchLogQueryWrapper = new QueryWrapper();
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getId()),"id",oYxLiveWatchLogQueryDTO.getId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getLiveShopId()),"live_shop_id",oYxLiveWatchLogQueryDTO.getLiveShopId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getShopId()),"shop_id",oYxLiveWatchLogQueryDTO.getShopId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getLiveId()),"live_id",oYxLiveWatchLogQueryDTO.getLiveId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchUserId()),"watch_user_id",oYxLiveWatchLogQueryDTO.getWatchUserId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchStartTime()),"watch_start_time",oYxLiveWatchLogQueryDTO.getWatchStartTime());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchEndTime()),"watch_end_time",oYxLiveWatchLogQueryDTO.getWatchEndTime());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchDuration()),"watch_duration",oYxLiveWatchLogQueryDTO.getWatchDuration());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchLength()),"watch_length",oYxLiveWatchLogQueryDTO.getWatchLength());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getNetSpeed()),"net_speed",oYxLiveWatchLogQueryDTO.getNetSpeed());
        oYxLiveWatchLogQueryWrapper.ge(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getCreateTimeStart()),"create_time",oYxLiveWatchLogQueryDTO.getCreateTimeStart());
        oYxLiveWatchLogQueryWrapper.le(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getCreateTimeEnd()),"create_time",oYxLiveWatchLogQueryDTO.getCreateTimeEnd());
        return oYxLiveWatchLogMapper.selectCount(oYxLiveWatchLogQueryWrapper);
    }
    /*** 
    * 自定义分页查询
    * @param currentPage 当前页
    * @param pageSize 分页大小
    * @param oYxLiveWatchLogEntity
    * @return Page
    **/
    @Override
    public Page selectYxLiveWatchLogPage(int currentPage,int pageSize,YxLiveWatchLogQueryDTO oYxLiveWatchLogQueryDTO)
    {
        if(currentPage <= 1)
        {
            currentPage = 1;
        }
        if(pageSize <= 0)
        {
            pageSize = 10;
        }
        Page<YxLiveWatchLogEntity> pageParams = new Page<>(currentPage,pageSize);
        QueryWrapper<YxLiveWatchLogEntity> oYxLiveWatchLogQueryWrapper = new QueryWrapper();
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getId()),"id",oYxLiveWatchLogQueryDTO.getId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getLiveShopId()),"live_shop_id",oYxLiveWatchLogQueryDTO.getLiveShopId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getShopId()),"shop_id",oYxLiveWatchLogQueryDTO.getShopId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getLiveId()),"live_id",oYxLiveWatchLogQueryDTO.getLiveId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchUserId()),"watch_user_id",oYxLiveWatchLogQueryDTO.getWatchUserId());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchStartTime()),"watch_start_time",oYxLiveWatchLogQueryDTO.getWatchStartTime());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchEndTime()),"watch_end_time",oYxLiveWatchLogQueryDTO.getWatchEndTime());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchDuration()),"watch_duration",oYxLiveWatchLogQueryDTO.getWatchDuration());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getWatchLength()),"watch_length",oYxLiveWatchLogQueryDTO.getWatchLength());
        oYxLiveWatchLogQueryWrapper.eq(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getNetSpeed()),"net_speed",oYxLiveWatchLogQueryDTO.getNetSpeed());
        oYxLiveWatchLogQueryWrapper.ge(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getCreateTimeStart()),"create_time",oYxLiveWatchLogQueryDTO.getCreateTimeStart());
        oYxLiveWatchLogQueryWrapper.le(ObjectUtil.isNotEmpty(oYxLiveWatchLogQueryDTO.getCreateTimeEnd()),"create_time",oYxLiveWatchLogQueryDTO.getCreateTimeEnd());
        return oYxLiveWatchLogMapper.selectPage(pageParams, oYxLiveWatchLogQueryWrapper);
    }
}
    

